/**
 * Created by Xiang on 2017/6/27
 */
/**
 * 随机整数
 */
let randomInt = function (min, max) {
    return min + Math.ceil(Math.random() * max);
};
let solve = function (template) {
    let known = template.known;
    let rabbit = template.variable.rabbit;
    let chicken = template.variable.chicken;
    let rabbitNum = (known.totalFoot - known.totalHead * chicken.foot) / (rabbit.foot - chicken.foot);
    let chickenNum = known.totalHead - rabbitNum;
    return {chickenNum, rabbitNum};
};
let randomQuestion2 = function (template) {
    template.answer.chicken = randomInt(2, 40);
    template.answer.rabbit = randomInt(2, 40);
    let totalHead = template.answer.chicken * template.variable.chicken.head + template.answer.rabbit * template.variable.rabbit.head;
    let totalFoot = template.answer.chicken * template.variable.chicken.foot + template.answer.rabbit * template.variable.rabbit.foot;
    template.known = {totalHead, totalFoot};
};
let questionTemplates = [
    {
        template: '鸡兔同笼,共有头40个,88只脚.求笼中鸡兔各有多少只?',
        content(){
            let known = this.known;
            return `鸡兔同笼,共有头${known.totalHead}个,${known.totalFoot}只脚.求笼中鸡兔各有多少只?`;
        },
        variable: {
            chicken: {name: '鸡', head: 1, foot: 2, unit: '只'},
            rabbit: {name: '兔', head: 1, foot: 4, unit: '只'},
        },
        attributeLabel: {
            head: '头',
            foot: '脚',
        },
        answer: {chicken: 36, rabbit: 4},
        known: {
            totalHead: 40,
            totalFoot: 88
        }
    },
    {
        template: '小明用35元钱正好买了2元和5元的邮票共10张,求这两种邮票名买了多少张?',
        content(){
            let known = this.known;
            return `小明用${known.totalFoot}元钱正好买了2元和5元的邮票共${known.totalHead}张,求这两种邮票名买了多少张?`;
        },
        variable: {
            chicken: {name: '2元', head: 1, foot: 2, unit: '张'},
            rabbit: {name: '5元', head: 1, foot: 5, unit: '张'},
        },
        attributeLabel: {
            head: '张',
            foot: '元钱',
        },
        answer: {chicken: 5, rabbit: 5},
        known: {
            totalHead: 10,
            totalFoot: 35
        }
    },
    {
        template: '52名同学去划船,一共乘坐11只船,其中每只大船坐6人,每只小船坐4人.求大船和小船各几只?',
        content(){
            let known = this.known;
            return `小明用${known.totalFoot}元钱正好买了2元和5元的邮票共${known.totalHead}张,求这两种邮票名买了多少张?`;
        },
        variable: {
            chicken: {name: '2元', head: 1, foot: 2, unit: '张'},
            rabbit: {name: '5元', head: 1, foot: 5, unit: '张'},
        },
        attributeLabel: {
            head: '张',
            foot: '元钱',
        },
        answer: {chicken: 5, rabbit: 5},
        known: {
            totalHead: 10,
            totalFoot: 35
        }
    },
    {
        template: '三年二班45个同学向爱心基金会共计捐款100元,其中11个同学每人捐1元,其他同学每人捐2元或5元,求捐2元和5元的同学各有多少人?'
    },
    {
        template: '松鼠妈妈采松籽,晴天每天可以采20个,雨天每天只能采12个.它一连8天共采了112个松籽,这八天有几天晴天几天雨天?'
    },
    {
        template: '一次数学竞赛共有20道题.做对一道题得5分,做错一题倒扣3分,刘冬考了52分,你知道刘冬做对了几道题?'
    },
    {
        template: '100个和尚吃了100个面包,大和尚1人吃3个,小和尚3人吃1个.求大小和尚各有多少个?'
    },
    {
        template: '有蜘蛛、蜻蜓、蝉三种动物共18只,共有腿118条,翅膀20对.问蜻蜓有多少只?（蜘蛛8条腿；蜻蜓6条腿,两对翅膀；蝉6条腿,一对翅膀）'
    },
];


export {
    questionTemplates,
    randomQuestion2
}